/**
 * 1) 修正ie6-9不支持placeholder
 * 2) 修正ie不支持oninput事件
 */
jQuery(function(){
	var JPlaceHolder = {
		    //检测
		    _check : function(){
		        return 'placeholder' in document.createElement('input');
		    },
		    //初始化
		    init : function(){
		        if(!this._check()){
		            this.fix();
		        }
		    },
		    //修复
		    fix : function(){
		        jQuery(':input[placeholder],textarea').each(function(index, element) {
		            var self = $(this), txt = self.attr('placeholder');
		            self.css('line-height',self.outerHeight(true)+'px');
		            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none',fontSize:'13px'}));
		            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
		            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, paddingLeft:paddingleft, color:'#aaa',fontSize:'13px',width:'auto',lineHeight:h+'px'}).appendTo(self.parent());
		            self.focusin(function(e) {
		                holder.hide();
		            }).focusout(function(e) {
		                if(!self.val()){
		                    holder.show();
		                }
		            });
		            holder.click(function(e) {
		                holder.hide();  
		                self.focus();
		            });
		        });
		    }
		};
    JPlaceHolder.init();
    
    if(!("oninput" in document.createElement("div"))){
    	$('input').each(function(i,elem){
    		var self = $(this);
    		self.on('keydown paste',function(event){
    			var oldValue=self.val();
    			 setTimeout(function(){
    	                if(oldValue!=self.val()){
    	                	self.trigger('input');
    	                }
    	         },0);
    		});
    	});
    }
    
});